import { createPinia, defineStore } from 'pinia';
import { createPersistedState } from 'pinia-plugin-persistedstate';
const createPersistUni = () => {
    return createPersistedState({
        storage: {
            getItem: uni.getStorageSync,
            setItem: uni.setStorageSync
        }
    })
}

export default {
    install(app) {
        const pinia = createPinia();
        pinia.use(createPersistUni());
        app.use(pinia);
        this.store();
        app.config.globalProperties.$store = app.config.globalProperties.$pinia.state.value.store;
    },
    store() {
        defineStore('store', {
            state: () => {
                return {
                    sys: {},
                    token: '',
                    user_info: {},
                    pay_addr: {}
                };
            },
            persist: true
        })();
    }
};
